JR.container.view = function($){
	return {
		init : function(){
			JR.container.view.back.init();
			JR.container.view.view.init();
			JR.container.view.link.init();
			JR.container.view.controller.init();
		}
	};
}(jQuery);

JR.container.view.controller = function($){
	
	var ContainerModel = function(){};
	ContainerModel.prototype = {
		setId : function(id){
			this.id = id;
		},
		setName : function(name){
			this.name = name;
		},
		setDesc : function(desc){
			if(desc == "" || desc ==null){
				desc = '无';
			}
			this.desc = desc;
		},
		setUrl : function(url){
			this.url = url;
		},
		setSurl : function(surl){
			this.surl = surl;
		},
		setTurl : function(turl){
			this.turl = turl;
		},
		getId : function(){
			return this.id;
		},
		getName : function(){
			return this.name;
		},
		getDesc : function(){
			return this.desc;
		},
		getUrl : function(){
			return this.url;
		},
		getSurl : function(){
			return this.surl;
		},
		getTurl : function(){
			return this.turl;
		}
	};
	
	var controller = {
		init : function(){
			this.url_view = JR.url2('container-view-exec.action');
			this.cid = $('#cid').val();
			this.load();
		},
		load : function(){
			JR.ajax(this.url_view, this.analyzeData, {id: this.cid});
		},
		analyzeData : function(res){
			var model = new ContainerModel();
			model.setId(res.id);
			model.setName(res.name);
			model.setDesc(res.description);
			model.setUrl(res.url);
			model.setSurl(res.surl);
			model.setTurl(res.turl);
			JR.container.view.view.show(model);
		}
	};
	
	return {
		init : function(){
			controller.init();
		}
	};
}(jQuery);

JR.container.view.view = function($){
	var view = {
		init : function(){
			this.container = $('#view');
			this.image = $('#image', this.container);
			this.name = $('#name .right', this.container);
			this.desc = $('#desc .right', this.container);
		},
		show : function(model){
			JR.container.view.link.render(model);
			
			this.image.empty();
			this.name.empty();
			this.desc.empty();
			
			this.name.text(model.name);
			this.desc.html(JR.utils.textarea(model.desc));
			this.desc.prepend($('<div>').addClass('min-height'));
			$.imgAuto().load(JR.statics.contextPath + model.surl, 300, 300).appendTo(this.image);
		}
	};
	
	return {
		init : function(){
			view.init();		
		},
		show : function(model){
			view.show(model);
		}
	};
}(jQuery);

JR.container.view.link = function($){
	
	var view = {
		init : function(){
			this.viewContainer = $('#view');
			this.container = $('.operation', this.viewContainer);
			this.id = $('#cid', this.viewContainer);
			this.edit = $('#edit', this.container);
			this.del = $('#del', this.container);
		},
		render : function(model){
			this.addEvents();
		},
		addEvents : function(){
			var th = this;
			this.del.click(function(){
				var result = confirm('确定要删除此集装箱吗？');
				if(result){
					th.delContainer();
				}
			});
			this.edit.click(function(){
				th.editContainer();
			});
		},
		getId : function(){
			return this.id.val();
		},
		delContainer : function(){
			this.viewContainer.block({
				message:null
			});
			var th = this;
			JR.ajax(JR.url2('container-delete.action'), function(){th.afterDel()}, {id: th.getId()});
		},
		afterDel : function(){
			this.viewContainer.unblock();
			this.viewContainer.block({
				message: '删除成功!<br/>页面正在跳转中...'
			});
			setTimeout(function(){
				JR.admin.loadx.showList(JR.statics.id);
			}, 1000);
		},
		editContainer : function(){
			JR.admin.loadx.show(JR.url2('container-edit.action'), {id: this.getId()});
		}
	};
	
	return {
		init : function(){
			view.init();	
		},
		render : function(model){
			view.render(model);
		}
	};
}(jQuery);

JR.container.view.back = function($){
	
	return {
		init : function(){
			$('.back').click(function(e){
				e.preventDefault();
				JR.admin.loadx.showList(JR.statics.id);
			});
		}
	};
}(jQuery);